#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int singleNumber(vector<int>& nums) {
        sort(nums.begin(), nums.end());
        vector<int>::iterator it = nums.begin();
        while (it != nums.end())
        {
            if (it + 1 == nums.end())
                return *it;
            if (*it != *(it + 1))
                return *it;
            int temp = *it;
            while (*it == temp)
                it++;
        }
        return 0;
    }
};